package com.example.knowman.common;

import com.example.knowman.entity.log4operate;
import com.example.knowman.mapper.Log4operateMapper;
import com.example.knowman.service.ILog4operateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Component
public class Log4Util {
    @Autowired
    private static ILog4operateService iLog4operateService;




    public static void recordOperateLog(String content) {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request1 = attributes.getRequest();
        String ipAddress=request1.getHeader("ip");
        String operator=request1.getHeader("staffCode");
        String recContent="用户"+operator+content;
//        log4operate temp=new log4operate();
//        temp.setContent(recContent);
//        temp.setIpAddress(ip);
//        temp.setOperator(staffCode);
        iLog4operateService.insertSingle(operator,recContent,ipAddress);
    }
//    public String listToString(List<String> list){
//
//        StringBuffer sb = new StringBuffer();
//        for (String s : list) {
//            sb.append("'").append(s).append("'").append(",");
//        }
//        String res="("+sb.toString().substring(0, sb.toString().length() - 1)+")";
//        return  res;
//    }
}
